# -*- coding = utf-8 -*-
# @Time : 2022/1/10 8:48
# @Author : 龙王赘婿_彪少
# @File : yzw2.py.py
# @Software: PyCharm

import openpyxl
import re


class YZW:
    def __init__(self):
        self.loadfile()
        self.printsheet()
        self.getsheet()
        self.ergodic()
        print("-" * 50)
        self.ergodic2()
        self.savefile()

    # 加载文件
    def loadfile(self):
        self.wb = openpyxl.load_workbook("../file/第二套数据.xlsx")

    # 打印表单
    def printsheet(self):
        print(self.wb.sheetnames)

    # 获取表单
    def getsheet(self):
        # 方式1
        self.ws = self.wb["Sheet1"]

    def ergodic(self):
        # 列遍历 带范围
        self.nameA = []
        num = 0
        for i in self.ws.iter_cols(min_row=1, max_row=5, min_col=2, max_col=2 + 50 - 1):
            num += 1
            # print(i[0].value, i[1].value, num)
            self.nameA.append(re.findall("(.+?)-11A-", i[0].value)[0])

        print(self.nameA)

    def savefile(self):
        self.wb.save("../file/第二套数据已处理.xlsx")

    def ergodic2(self):
        # 列遍历 带范围
        self.nameB = []
        num = 0
        for i in self.ws.iter_cols(min_row=1, max_row=5, min_col=2 + 50):
            num += 1
            # print(i[0].value, i[1].value, num)
            self.nameB.append(re.findall("(.+?)-0[1-2][A-B]-", i[0].value)[0])

        num2 = 1
        for i in self.nameA:
            num2 += 1
            if self.nameB.count(i):
                # 匹配位置 列数
                index = self.nameB.index(i) + 52
                # 复制到当前位置
                for j in range(0, 7):
                    self.ws.cell(9 + j, num2).value = self.ws.cell(1 + j, index).value


if __name__ == "__main__":
    yzw = YZW()